package com.lhy.common.web.wrapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lhy.common.web.entity.DbField;

public abstract class AbstractLikeSearchComparator extends AbstractSearchComparator {


    @Override
    public void accept(QueryWrapper queryWrapper, DbField dbField) {
        checkSpecialWord(dbField.getValue());
        this.exeAccept(queryWrapper, dbField);
    }

    protected abstract void exeAccept(QueryWrapper queryWrapper, DbField dbField);

    /**
     * 检查查询的关键字中是否含有特殊字符，如果有则抛出异常
     *
     * @param val
     */
    protected void checkSpecialWord(String val) {
        if (val.contains("_") || val.contains("%")) {
            throw new RuntimeException("搜索关键字中含有_或%特殊字符,不允许搜索");
        }
    }
}
